/*
  Copyright (C) 2011, Kyungjoo Kim
  
  This file is part of UHM (Unassembled HyperMatrix) sparse direct solver.
  
  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Also add information on how to contact you by electronic and paper mail.
  
  
  Kyungjoo Kim
  iamkyungjoo@gmail.com
*/
#include "uhm.hxx"

#include "uhm/interf/pardiso.hxx"
#include "uhm/wrapper/pardiso_fort.hxx"

//----------------------------------------------------------------------
// FORTRAN INTERFACE
//----------------------------------------------------------------------

// ** PARDISO
//----------------------------------------------------------------------
void UHM_C2F(uhm_mesh_export_matrix_pardiso)  ( uhm_fort_p   *mesh,
                                                uhm_fort_p   *pardiso,
                                                uhm_fort_int *n_rhs,
                                                uhm_fort_int *is_sym) {
  uhm::Mesh m = (uhm::Mesh)( *mesh );
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  m->export_matrix(p, *n_rhs, *is_sym);
}

void UHM_C2F(uhm_pardiso_create)              ( uhm_fort_p   *pardiso,
                                                uhm_fort_int *datatype ) {
  uhm::interf::Pardiso p = new uhm::interf::Pardiso_( *datatype );
  *pardiso = (uhm_fort_p)p;
}

void UHM_C2F(uhm_pardiso_delete)              ( uhm_fort_p   *pardiso ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  delete p;
}

void UHM_C2F(uhm_pardiso_is_complex)          ( uhm_fort_p   *pardiso,
                                                uhm_fort_int *flag) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  if (p->is_complex()) *flag = 1;
  else *flag = 0;
}

void UHM_C2F(uhm_pardiso_set_show_n_rhs)      ( uhm_fort_p   *pardiso,
                                                uhm_fort_int *show_n_rhs) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->set_show_n_rhs(*show_n_rhs);
}

void UHM_C2F(uhm_pardiso_set_phase)           ( uhm_fort_p   *pardiso,
                                                uhm_fort_int *phase) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->set_phase(*phase);
}

void UHM_C2F(uhm_pardiso_run)                 ( uhm_fort_p   *pardiso ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->run();
}
                                                
void UHM_C2F(uhm_pardiso_set_iparm)           ( uhm_fort_p   *pardiso,
                                                uhm_fort_int *idx,
                                                uhm_fort_int *val ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->set_iparm( *idx, *val );
}

void UHM_C2F(uhm_pardiso_set_dparm)           ( uhm_fort_p   *pardiso,
                                                uhm_fort_int *idx,
                                                uhm_fort_double *val ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->set_dparm( *idx, *val );
}

void UHM_C2F(uhm_pardiso_init)                ( uhm_fort_p   *pardiso ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->init();
}

void UHM_C2F(uhm_pardiso_analyze)             ( uhm_fort_p   *pardiso ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->analyze();
}

void UHM_C2F(uhm_pardiso_decompose)           ( uhm_fort_p   *pardiso ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->decompose();
}

void UHM_C2F(uhm_pardiso_solve)               ( uhm_fort_p   *pardiso ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->solve();
}

void UHM_C2F(uhm_pardiso_export_matrix_uhm)   ( uhm_fort_p   *pardiso,
                                                uhm_fort_p   *mesh ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  uhm::Mesh m = (uhm::Mesh)( *mesh );
  p->export_matrix(m);
}

void UHM_C2F(uhm_pardiso_finalize)            ( uhm_fort_p   *pardiso ) {
  uhm::interf::Pardiso p = (uhm::interf::Pardiso)( *pardiso );
  p->finalize();
}

